<?php include('./templete/public/head.php') ?>
 <!--<div class="head">
   <div class="headpd">
        <a class="iconfont posiabstion" href="javascript:history.go(-1)">&#xe606;</a>
        方案商城
    </div>
</div>
<hr style="height: .6rem;border: none;margin: 0;"/>-->
<div class="bgpic smpic" style="background-image: url(<?php foreach ($project as $v){ if($v['id']==$thisids){ echo $v['imgbanner'];} }?>);"></div>
<div class="leave-hint"><p>提示：请留下您的真实信息，平台会主动联系您！</p></div>
<div class="leave-table shop-table">
    <table>
        <tr>
            <td width="34.375%">意向方案</td>
            <td width="65.625%">
                <select name="projectid" id="projectid">
                    <?php foreach ($project as $v){ ?>
                    <option  value="<?php echo $v['id'] ?>" <?php if($v['id']==$thisids){ ?> selected="selected"<?php } ?>><?php echo $v['name'] ?></option>
                    <?php } ?>
                </select>
            </td>
        </tr>
        <tr>
            <td>意向车型</td>
            <td><input type="text" name="yixiang" id="yixiang" placeholder="请输入意向车型"/></td>
        </tr>
    </table>
</div>
<hr class="eee"/>
<div class="leave-table shop-table">
    <table>
        <tr>
            <td width="34.375%">姓名</td>
            <td width="65.625%">
                <input type="text" name="username" id="username" placeholder="请输入姓名"/>
            </td>
        </tr>
        <tr>
            <td>身份证号</td>
            <td><input type="text" name="cardid" id="cardid" placeholder="请输入身份证号后四位"/></td>
        </tr>
        <tr>
            <td>手机号</td>
            <td><input type="text" name="phone" id="phone" placeholder="请输入手机号"/></td>
        </tr>
        <tr>
            <td>手机验证码</td>
            <td class="clearfix"><input type="text" name="checknumber" id="checknumber" placeholder="请输入手机验证码"style="width:60%  !important; float: left;"/><a href="#" class="shopbtn fl">获取验证码</a></td>
        </tr>
<!--        <tr>-->
<!--            <td>城市</td>-->
<!--            <td>-->
<!--                <div class="content-block clearfix">-->
<!--                    <input id="demo1-map" type="text" readonly="" name="city" placeholder="城市选择特效"  value="上海市,静安区"/>-->
<!--                    <input id="value1" type="hidden" value="20,234,504"/>-->
<!--                    <i class="iconfont font30 fr">&#xe630;</i>-->
<!--                </div>-->
<!--            </td>-->
<!--        </tr>-->
           <tr>
            <td>城市</td>
            <td>
                <div class="content-block clearfix">
                    <select id="province" name="privince" onchange="getCity();">
                        <option value= 0 >上海</option>
                        <option value= 1 >北京</option>
                        <option value= 2 >天津</option>
                        <option value= 3 >重庆</option>
                        <option value= 4 >河北</option>
                        <option value= 5 >山西</option>
                        <option value= 6 >内蒙古</option>
                        <option value= 7 >辽宁</option>
                        <option value= 8 >吉林</option>
                        <option value= 9 >黑龙江</option>
                        <option value= 10 >江苏</option>
                        <option value= 11 >浙江</option>
                        <option value= 12 >安徽</option>
                        <option value= 13 >福建</option>
                        <option value= 14 >江西</option>
                        <option value= 15 >山东</option>
                        <option value= 16 >河南</option>
                        <option value= 17 >湖北</option>
                        <option value= 18 >湖南</option>
                        <option value= 19 >广东</option>
                        <option value= 20 >广西</option>
                        <option value= 21 >海南</option>
                        <option value= 22 >四川</option>
                        <option value= 23 >贵州</option>
                        <option value= 24 >云南</option>
                        <option value= 25 >西藏</option>
                        <option value= 26 >陕西</option>
                        <option value= 27 >甘肃</option>
                        <option value= 28 >宁夏</option>
                        <option value= 29 >青海</option>
                        <option value= 30 >新疆</option>
                        <option value= 31 >香港</option>
                        <option value= 32 >澳门</option>
                        <option value= 33 >台湾</option>
                    </select>
                    <select id="city" name="city"></select>
                </div>
            </td>
        </tr>
        <tr>
            <td>购车时间</td>
            <td>
                <input id="demo-date" name="time" readonly placeholder="请输入日期">
                <i class="iconfont font30 fr">&#xe630;</i>
            </td>
        </tr>
        <tr>
            <td>性别</td>
            <td>
                <select class="w90" name="sex" id="sex">
                    <option>男</option>
                    <option>女</option>
                </select>
                <i class="iconfont font30 fr">&#xe630;</i>
            </td>
        </tr>
        <tr>
            <td>职业</td>
            <td>
                <select class="w90" name="zhiye" id="zhiye">
                    <?php foreach($worktype as $v){ ?>
                    <option><?php echo $v['name'] ?></option>
                    <?php } ?>
                </select>
                <i class="iconfont font30 fr">&#xe630;</i>
            </td>
        </tr>
        <tr>
            <td>收入</td>
            <td>
                <select class="w90" name="yuegong" id="yuegong">
                    <?php foreach($yuegong as $v){ ?>
                        <option><?php echo $v['name'] ?></option>
                    <?php } ?>
                </select>
                <i class="iconfont font30 fr">&#xe630;</i>
            </td>
        </tr>
		<tr>
			<td>购车需求</td>
			<td width="99.890625%"><textarea id="need" name="need" placeholder="请输入购车需求"></textarea></td>
		</tr>
    </table>
</div>
<div class="btn"><a class="subbutton">提交</a></div>
<!--footer-->
<script src="_js/ss.js"></script>
<?php include('./templete/public/foot.php') ?>
<script>
    $('.shopbtn').bind('click',getcode);
    function getcode() {
        //alert(123);
        var phone = $('#phone').val();
        //alert(phone)
        if(!phone){
            layer.msg('请输入手机号');return false;
        }
        var regForYD=/^((13[4-9])|(15([0-2]|[7-9]))|(18[2|3|4|7|8])|(178)|(147))[\d]{8}$/;    //移动
        var regForLT=/^((13[0-2])|(145)|(15[5-6])|(176)|(18[5-6]))[\d]{8}$/;   //联通
        var regForDX=/^((133)|(153)|(18[0|1|9])|(177))[\d]{8}$/;    //电信
        //alert(regForYD.test(phone));
        if(!(regForDX.test(phone))&&!(regForYD.test(phone))&&!(regForLT.test(phone))){
            layer.msg('请输入正确的手机号');return false;
        }
        $.ajax({
            url:'<?php echo url('sendmsg') ?>',
            type:'post',
            dataType:'json',
            data:{
                phone:phone,
            },
            success:function (data) {
                if(data.code == 1){
                    $('.shopbtn').unbind('click');
                    countDownNum({//倒计时
                        ele:$(".shopbtn"),
                        num:60,
                        text:'s',
                        callback:function(){
                            $('.shopbtn').bind('click',getcode);
                            $('.shopbtn').text('重新发送');
                        }
                    });
                    layer.msg(data.msg);
                }else{
                    $('.shopbtn').show()
                }
            }
        })

    };

    function countDownNum(options){
        var obj = {
            beforeText:'',//默认倒计时前面文字
            text:'S',//默认倒计时后面文字
            num:60,//默认倒计时120秒
            ele:'.shopbtn'//默认倒计时元素
        };
        for(var i in options){
            obj[i] = options[i];
        }
        window.countTimer = null;
        clearInterval(window.countTimer);
        if(!Number(obj.num)){
            console.error('请传入合法数字');
            return false;
        };
        var defaultHtml = $(obj.ele).html();
        $(obj.ele).html(obj.beforeText + '' + obj.num + obj.text);
        window.countTimer = setInterval(function(){
            obj.num--;
            if(obj.num<0){
                if(typeof obj.callback == 'function'){
                    obj.callback.call($(obj.ele));
                }else{
                    $(obj.ele).html(defaultHtml);
                }
                clearInterval(window.countTimer);
                window.countTimer = null;
            }else{
                $(obj.ele).html(obj.beforeText + '' + obj.num + obj.text);
            }
        },1000)
    }




    $('.subbutton').click(function () {
        var projectid = $("#projectid").val();
        //alert(projectid);
        if(!projectid){
            layer.msg('请选择方案');return false;
            //msg('请选择方案')
        }
        var yixiang = $("#yixiang").val();
        if(!yixiang){
            layer.msg('请填写意向车型');return false;
        }
        var　username = $('#username').val();
        //alert(username)
        if(!username){
            layer.msg('请输入您的姓名');return false;
        }
        var　cardid = $('#cardid').val();
        //alert(username)
        if(!cardid){
            layer.msg('请输入身份证号后四位');return false;
        }
        if(cardid.length>5){
            layer.msg('身份证号后四位超过长度');return false;
        }
        var phone = $('#phone').val();
        //alert(phone)
        if(!phone){
            layer.msg('请输入手机号');return false;
        }
        var regForYD=/^((13[4-9])|(15([0-2]|[7-9]))|(18[2|3|4|7|8])|(178)|(147))[\d]{8}$/;    //移动
        var regForLT=/^((13[0-2])|(145)|(15[5-6])|(176)|(18[5-6]))[\d]{8}$/;   //联通
        var regForDX=/^((133)|(153)|(18[0|1|9])|(177))[\d]{8}$/;    //电信
        //alert(regForYD.test(phone));
        if(!(regForDX.test(phone))&&!(regForYD.test(phone))&&!(regForLT.test(phone))){
            layer.msg('请输入正确的手机号');return false;
        }
        var checknumber= $('#checknumber').val();
        if(!checknumber){
            layer.msg('请输入验证码');return false;
        }
        var province = $('#province option:selected').text()
            //alert(city);
        if(!province){
            layer.msg('请选择所在省');return false;
        }
        var city = $('#city option:selected').text()
            //alert(city);
        if(!city){
            layer.msg('请选择所在城市');return false;
        }
        var time = $('#demo-date').val();
        //if(!time){
        //    layer.msg('请选择购车时间');return false;
        //}
        var sex = $('#sex').val();
        //if(!sex){
        //    layer.msg('请选择性别');return false;
        //}
        var zhiye=$('#zhiye').val();
        var yuegong =$('#yuegong').val();
		var need=$('#need').val();
        $('.okbtn').hide();
        $.ajax({
            url:'<?php echo url('apply') ?>',
            type:'post',
            dataType:'json',
            data:{
                projectid:projectid,
                yixiang:yixiang,
                username:username,
                cardid:cardid,
                phone:phone,
                checknumber:checknumber,
                time:time,
                province:province,
                city:city,
                sex:sex,
                zhiye:zhiye,
                yuegong:yuegong,
				need:need
            },
            success:function (data) {
                if(data.code == 1){
                    layer.msg(data.msg);
                    setTimeout(function () {
                        location.href=data.url;
                    },1000)
                }else{
                    layer.msg(data.msg);
                    $('.subbutton').show()
                }
            }
        })
    })



    var calendar = new datePicker();
    calendar.init({
        'trigger': '#demo-date', /*按钮选择器，用于触发弹出插件*/
        'type': 'date',/*模式：date日期；datetime日期时间；time时间；ym年月；*/
        'minDate':'1900-1-1',/*最小日期*/
        'maxDate':'2100-12-31',/*最大日期*/
        'onSubmit':function(){/*确认时触发事件*/
            var theSelectData=calendar.value;
        },
        'onClose':function(){/*取消时触发事件*/
        }
    });

</script>

